/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('nbftestpop', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model TbTestApiRequest {
  query?: {
    teat?: string(name='teat'),
  }(name='query'),
}

model TbTestApiShrinkRequest {
  queryShrink?: string(name='query'),
}

model TbTestApiResponseBody = {
  bizException?: boolean(name='bizException'),
  current?: int32(name='current'),
  errorCode?: string(name='errorCode'),
  errorMsg?: string(name='errorMsg'),
  pageSize?: int32(name='pageSize'),
  requestId?: string(name='requestId'),
  result?: string(name='result'),
  success?: boolean(name='success'),
  total?: long(name='total'),
  totalPage?: int32(name='totalPage'),
}

model TbTestApiResponse = {
  headers: map[string]string(name='headers'),
  body: TbTestApiResponseBody(name='body'),
}

async function tbTestApi(request: TbTestApiRequest): TbTestApiResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return tbTestApiWithOptions(request, headers, runtime);
}

async function tbTestApiWithOptions(tmpReq: TbTestApiRequest, headers: map[string]string, runtime: Util.RuntimeOptions): TbTestApiResponse {
  Util.validateModel(tmpReq);
  var request = new TbTestApiShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.query)) {
    request.queryShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.query, 'query', 'json');
  }
  var query : map[string]any= {};
  if (!Util.isUnset(request.queryShrink)) {
    query['query'] = request.queryShrink;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'TbTestApi',
    version = 'tb_test51_0_0',
    protocol = 'HTTP',
    pathname = `/tb_test5/1_0_0/tbTestApi`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model TbTestApiBRequest {
  dto?: {
    big?: float(name='big'),
    date?: long(name='date'),
    dou?: float(name='dou'),
    test?: string(name='test'),
  }(name='dto'),
  id?: int32(name='id'),
}

model TbTestApiBResponseBody = {
  bizException?: boolean(name='bizException'),
  current?: int32(name='current'),
  errorCode?: string(name='errorCode'),
  errorMsg?: string(name='errorMsg'),
  pageSize?: int32(name='pageSize'),
  requestId?: string(name='requestId'),
  result?: {
    big?: float(name='big'),
    date?: long(name='date'),
    dou?: float(name='dou'),
    test?: string(name='test'),
  }(name='result'),
  success?: boolean(name='success'),
  total?: long(name='total'),
  totalPage?: int32(name='totalPage'),
}

model TbTestApiBResponse = {
  headers: map[string]string(name='headers'),
  body: TbTestApiBResponseBody(name='body'),
}

async function tbTestApiB(request: TbTestApiBRequest): TbTestApiBResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return tbTestApiBWithOptions(request, headers, runtime);
}

async function tbTestApiBWithOptions(request: TbTestApiBRequest, headers: map[string]string, runtime: Util.RuntimeOptions): TbTestApiBResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.dto)) {
    body['dto'] = request.dto;
  }
  if (!Util.isUnset(request.id)) {
    body['id'] = request.id;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'TbTestApiB',
    version = 'tb_test51_0_0',
    protocol = 'HTTP',
    pathname = `/tb_test5/1_0_0/tbTestApiB`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

